package com.um.jdy.ykc.command;

import com.um.jdy.ykc.utils.RadixsUtil;
import lombok.Data;

/**
 * 充电结束（充电桩->运营平台）
 *
 * @author 甘天伟
 * @since 2022/6/28
 * 版权所有 广州优匠科技有限公司
 */
@Data
public class Cmd19ChargeEnd extends YkcCommand {

    /**
     * 交易流水号：16个字节
     */
    private String transactionNo;

    /**
     * 桩编码：7个字节
     */
    private String code;

    /**
     * 枪号：1个字节
     */
    private int gunNo;

    /**
     * BMS 中止荷电状态 SOC：1个字节
     */
    private int bmsSoc;

    /**
     * BMS 动力蓄电池单体最低电压：2个字节
     */
    private int bmsSingleBatteryMinVoltage;

    /**
     * BMS 动力蓄电池单体最高电压：2个字节
     */
    private int bmsSingleBatteryMaxVoltage;

    /**
     * BMS 动力蓄电池最低温度：1个字节
     */
    private int bmsBatteryMinTemperature;

    /**
     * BMS 动力蓄电池最高温度：1个字节
     */
    private int bmsBatteryMaxTemperature;

    /**
     * 电桩累计充电时间：2个字节
     */
    private int totalChargeMinutes;

    /**
     * 电桩输出能量：2个字节
     */
    private int totalChargePower;

    /**
     * 电桩充电机编号：4个字节
     */
    private int chargerNo;

    @Override
    public void parseBytes(byte[] bytes) {
        super.parseBytes(bytes);
        transactionNo = RadixsUtil.bytesToHexString(readBytes(data, 0, 16));
        code = RadixsUtil.bytesToHexString(readBytes(data, 16, 7));
        gunNo = RadixsUtil.byteToInteger(data[23]);
        bmsSoc = RadixsUtil.byteToInteger(data[24]);
        bmsSingleBatteryMinVoltage = RadixsUtil.bytesToInteger(readBytes(data, 25, 2));
        bmsSingleBatteryMaxVoltage = RadixsUtil.bytesToInteger(readBytes(data, 27, 2));
        bmsBatteryMinTemperature = RadixsUtil.byteToInteger(data[28]);
        bmsBatteryMaxTemperature = RadixsUtil.byteToInteger(data[29]);
        totalChargeMinutes = RadixsUtil.bytesToInteger(readBytes(data, 30, 2));
        totalChargePower = RadixsUtil.bytesToInteger(readBytes(data, 32, 2));
        chargerNo = RadixsUtil.bytesToInteger(readBytes(data, 34, 4));

        transactionNo = RadixsUtil.getTransactionNo(transactionNo);
        code = RadixsUtil.getCode(code);
    }
}
